package net.lovesrc.support.service.mobile;

import com.alibaba.fastjson.JSONObject;
import com.zhouzhou.fastjava.http.Requests;

/**
 * 获取手机号对应的信息，省份，城市，运营商
 */
public class DefaultMobileService implements MobileService {

    @Override
    public MobileZone getZone(String mobile) {
        JSONObject resJson = Requests.get("https://cx.shouji.360.cn/phonearea.php?number=" + mobile)
                .execute()
                .asJson();
        int code = resJson.getIntValue("code");
        if (code == 0) {
            JSONObject data = resJson.getJSONObject("data");
            return new MobileZone(
                    data.getString("province"),
                    data.getString("city"),
                    data.getString("sp")
            );
        }
        return null;
    }

}
